
// 普通二叉树
struct Node* connect(struct Node* root) {
	if (root == NULL) return root;
    struct Node *dummy = malloc(sizeof(*dummy));
    dummy->next = NULL; // 哨兵，可指示下一层的头；先设置为NULL，表示没有下一层节点
    struct Node *p, *cur = root;
    while (cur) {   
        p = dummy;  
        while (cur) {   //遍历当前层，为下一层建立next
            if (cur->left) {    //存在左节点
                p->next = cur->left;
                p = p->next;
            }
            if (cur->right) {   //存在右节点
                p->next = cur->right;
                p = p->next;
            }
            cur = cur->next;
        }
        cur = dummy->next;  //下一层
        dummy->next = NULL; 
    }
    free(dummy);
    return root;
}